package net.hn.hnms.biz.safety.vehicle.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.common.jpa.utils.HqlUtils;
import net.hn.hnms.biz.common.jpa.utils.ResponsePage;
import net.hn.hnms.biz.safety.vehicle.domain.CarInspectEntity;
import net.hn.hnms.biz.safety.vehicle.repository.CarInspectRepository;
import net.hn.hnms.sys.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.EntityManager;
import java.util.List;

/**
 * 智呈物联 pan'sx
 * 2022/10/10 10:27
 * 1.0 version
 */
@RestController
@RequestMapping("riskMonitor/vehicle")
@Api(value = "井口检车", tags = {"井口检车"})
public class VehicleController {
    @Autowired
    private CarInspectRepository carInspectRepository;
    @Autowired
    @Qualifier("vehicleEntityManager")
    private  EntityManager vehicleEntityManager;


    @GetMapping("tables")
    @ApiOperation("表格数据查询")
    public R<ResponsePage<CarInspectEntity>> tables(@RequestParam(defaultValue = "0") int pageNum, @RequestParam(defaultValue = "20") int pageSize, CarInspectEntity carInspect) {
        PageRequest pageRequest = PageRequest.of(pageNum, pageSize);
        List<CarInspectEntity> all = carInspectRepository.findAll();
        ResponsePage<CarInspectEntity> page = HqlUtils.findPage(vehicleEntityManager, carInspect,
                pageRequest, "", Sort.by(Sort.Direction.DESC, "checkTime"));
        return R.ok(page);
    }

}
